All Questions
39 questions
1vote
1answer
7kviews
I received error "bash: line 1: [: -ne: unary operator expected" after run the below script
This script provides the expected output, but throw the error "bash: line 1: [: -ne: unary operator expected". Techies help to fix this. #!/bin/bash USR="root" # Email SUBJECT="NTP Service Status ...
0votes
2answers
2kviews
Run ssh command without quotes
You can execute a command on a remote server using ssh user@host 'the command' but is there a way to execute the command without quotes? (I am on BSD and using OpenSSH)
1vote
3answers
620views
SSH with Command Doesn't Run as an Alias
I have the following command to remote into a local server and tail -f the latest log file for an application that I have. The command works perfectly fine from the command line - ssh user@hostname ...
3votes
4answers
36kviews
get output of this command from another server via ssh
I'm trying to ssh into a server and get the system uptime using a specific command but it's failing to execute. this would work locally on almost all unix systems startuptime=`uptime | awk '{print $...
15votes
3answers
5kviews
How do ssh remote command line arguments get parsed
I've seen the questions and answers about needing to double-escape the arguments to remote ssh commands. My question is: Exactly where and when does the second parsing get done? If I run the ...
3votes
4answers
7kviews
Avoid escaping of double quotes
I have some commands I want to execute in a bash script. Now when we use single quotes the variable is taken literal and not the value. So doing e.g. ls "$SOME_DIR" is not the same as ls '$SOME_DIR' ...
2votes
1answer
10kviews
Send variable with EOF and use host variable [duplicate]
I want to send variable from source to host, and exec host script. Here is my code : var1=1 ssh -p 42 root@xxx /bin/bash << EOF var2=2 echo $var1 echo $var2 EOF Return : 1 var1=1 ssh -p ...
0votes
1answer
803views
Date command is not working in remote server when running using a script
I am running below command from a script from a remote server, but getting error No such file or directory ssh -t -t [email protected] \"sudo mysql nss_mysql < /home/user/scripts/Db_nss_mysql-`date ...
5votes
2answers
2kviews
How to re-write this function to avoid argument injection
I have a function in my .bashrc file that allows me to run a script on a remote server with arguments via ssh. Currently, the function contains: function runMyScript { if [ $1 = "s3" ] then ...
2votes
2answers
5kviews
How to escape quotes in shell within both usage of ssh and sudo?
In one word: question and example could test locally: sh -c "echo 'how to print single quote here'" details: I have a config like this: upload_server = ('192.168.1.1', 10051) now I need a shell ...
2votes
1answer
1kviews
Syntax error with variable containing quotes
I have a bunch of Linux machines behind 2 gateways. To connect to set one I do ssh -o ProxyCommand="ssh gateway1 nc %h %p" machines_behind_1 ssh -o ProxyCommand="ssh gateway2 nc --proxy %h %p --...
4votes
2answers
3kviews
Why some commands don't load user environment when executed with ssh? (while other do)
On a target machine (OS X El Capitan) I have brew in /usr/local/bin. When I try to get brew's path I get no result: # ssh [email protected] -p 2222 which brew # Troubleshooting: brew is in /usr/local/...
5votes
2answers
15kviews
Passing a list of two PIDs to xargs only kills the first using ssh
I'm retrieving a list of two PIDs that I want to kill. My pipeline looks something like ps -ef | grep foo | grep -v grep | awk {'print $2'} | xargs kill -9 Both processes are killed when executing ...
1vote
1answer
2kviews
Run for loop via ssh
Good day All, I'm attempting to run a for loop via SSH. The loop is used to get the last login of each user that has an account on the server, ssh 172.20.2.1 '''for i in `cat /etc/passwd | awk -F: '{...
2votes
2answers
1kviews
Exported variables inside ssh session are empty
I am trying to export a variable inside a ssh session and reference the variable in the next write command. sshpass -p "password" ssh -t -t my-box <<EOF export newUrl="this is a url" sudo -...